home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / amos / amoslist-0295.lzh / AMOSLIST / text0033.txt < prev    next >
Encoding:
Text File  |  1995-03-01  |  3.9 KB  |  103 lines

  1. On Thu, 2 Feb 1995, Mike Crowl wrote:
  2.  
  3. > Giday all,
  4. > just looking for some help in writing a tetris game. The bit I'd like 
  5. > some help with is how you would check to see if the block had hit another 
  6. > block and so on.
  7. > Any help would be much appreciated.
  8. > Ben Crowl
  9.  
  10. Gday Ben (and all you others)
  11.     
  12.     First of all I would like to issue a disclaimer :) It is 
  13. semester one exma week at my university and I last went to bed 4 days 
  14. ago, so forgive any minor errors in my code.
  15.     
  16.     OK. To drop pieces in Tetris, an array thje size of the playing 
  17. area is created eg 11*25 (X*Y). This 2-dimensional array is filled with 
  18. zeros to represnt no pieces. When a piece enters thje playing area, the 
  19. area it occupies is filled with (for example) 1.
  20.  
  21.     A lovely ascii diagram will help here.
  22.  
  23. 1. No pieces
  24. 2. L-shape just entering
  25. 3. L-shape a few moves on
  26. 4. L-shape after hitting the bottom
  27. 5. Square almost at the bottom
  28. 6. Square colliding with L-shape
  29.  
  30. grid is 8*9 in this example 
  31.  
  32. 1. 00000000  2. 00200000  3. 00000000  4. 00000000  5. 00000000  6. 00000000
  33.    00000000    00222000     00200000      00000000     00000000     00000000
  34.    00000000    00000000     00200000      00000000     00000000     00000000
  35.    00000000    00000000     00222000      00000000     00000000     00000000
  36.    00000000    00000000     00000000      00000000     00000000     00000000
  37.    00000000    00000000     00000000      00000000     00001100     00000000
  38.    00000000    00000000     00000000      00200000     00201100     00201100
  39.    00000000    00000000     00000000       00200000     00200000     00201100
  40.    00000000    00000000     00000000      00222000     00222000     00222000
  41.  
  42. The number 2 represents the code for the l-shape
  43. The number 1 represents the code for the square
  44.  
  45. By now you will probably have realised how it all works. But I shall 
  46. explain for the hard of thinking :)
  47.  
  48. Before a piece drops, its new position in the array is calculated. If 
  49. this collides with any other numbers then the piece is stuck. It has hit 
  50. the bottom.
  51.  
  52. A way for calculating collisions (just appeared off the top of my head) 
  53. is to calculate a checksum for each horizontal line before and after the 
  54. move. If the 'After move' sum is different to the 'Before move' sum then 
  55. subtract the id code of the current piece (unless the piece is a square 
  56. then subtract 2*id code). If the answer is different to the 'Before sum' 
  57. no, then the new piece has collided.
  58.  
  59. What the ????
  60.  
  61. Explanation: The horizontal line in the array has a nujmber indicating a 
  62. part of each block. If you add all these and then move the piece and then 
  63. recalculate, a new id number may have appeared on the horizontal line, eg if 
  64. a long thin block appears. If there is a difference, then the id code is 
  65. subtracted from the 'after' total (if the piece is not one block wide then 
  66. n*id code are subtracted where n is width). This subtraction effectively 
  67. removes the block. If the answer of the processed 'After' is different to 
  68. the 'Before' checksum, it means that an id code apart from the moving 
  69. block one was removed. In other words, putting the new piece in the array 
  70. obscured a previous code, which would signify a collision.
  71.  
  72. 1. one line before new piece arrives
  73.  
  74.     01110020  checksum = 5
  75.  
  76. 2. one line with new piece. this piece has been moving down unobstructed. 
  77. this is its first encounter with other pieces. represented by letter code 3
  78.  
  79.     01110030  checksum = 6
  80.  
  81. checksum after - checksum before = 1. Aha. Different. This means a piece 
  82. has arrived. Subtract the id code of the new piece
  83.  
  84. 1 - 3 = -2
  85.  
  86. Aha. Not equal to 0. This indicates that a id code was removed when this 
  87. piece arrived. Look at the diagrams and you will see that an id code of 
  88. '2' was removed (7th column)
  89.  
  90. If anyone needs further explanation, then feel free to email me, 
  91. privately or thru the list.
  92.  
  93. See ya
  94.  
  95. --
  96. t.r.matthews@bradford.ac.uk         Founder Member of the 'Irresponsible Club'
  97. Email me for details on how to join.  Must complete an *initiation* *ceremony*
  98.  
  99.  
  100.